<template>
  <div class="header">
    <div class="header-inner">
      <ul class="navlist">
        <li
          v-for="(item, index) in navlist"
          :key="index"
          :class="{ active: cur == index }"
          @click="Jump(item, index)"
        >
          {{ item.name }}
        </li>
      </ul>
      <h1 class="loginout" @click="loginout">退出</h1>
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
export default {
  data() {
    return {
      cur: 0,
      navlist: [
        {
          name: "培训学习",
          path: "/main"
        },
        {
          name: "在线考试",
          path: "/exam"
        },
        {
          name: "我的",
          path: "/mine"
        }
      ]
    };
  },
  mounted() {
    this.cur = sessionStorage.getItem("cur");
  },
  methods: {
    Jump(item, index) {
      this.$router.push({ path: item.path });
      this.cur = index;
      sessionStorage.setItem("cur", this.cur);
    },
    loginout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$store.dispatch('LogOut').then(() => {
            Cookies.remove("id");
          Cookies.remove("ksSpecialty");
          Cookies.remove("session_templateName");
          Cookies.remove("shijuanid");
          Cookies.remove("session_time");
          Cookies.remove("session_total");
          location.href = '/main';
        })
        })
        .catch(() => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: 100%;
  background: #4377fb;
  font-size: 0.18rem;
}
.header-inner {
  max-width: 1230px;
  margin: 0 auto;
  position: relative;
}
.loginout {
  position: absolute;
  right: 20px;
  top: 20px;
  color: #fff;
  cursor: pointer;
}
.navlist {
  max-width: 360px;
  height: 100%;
  display: flex;
  li {
    color: #fff;
    flex: 1;
    cursor: pointer;
    height: 100%;
    line-height: 0.58rem;
    text-align: center;
    border-bottom: 2px solid #188fff00;
    transition: border-color 0.3s, background-color 0.3s, color 0.3s;
    font-weight: 500;
  }
  li:hover {
    background-color: rgb(54, 105, 235) !important;
  }
}
.active {
  color: rgb(255, 213, 80) !important;
  border-bottom: 2px solid rgb(255, 213, 80) !important;
}
</style>
